using System.Text;
using Newtonsoft.Json;

namespace WxLib.Model
{
    public class SyncKey
    {
        public int Count { get; set; }
        public SyncKeyPair[] List { get; set; }

        public string ToJson()
        {
            string jsonResult = "\"SyncKey:\":";
            return jsonResult + JsonConvert.SerializeObject(new SyncKey
            {
                Count = Count,
                List = List
            });
        }
        public override string ToString()
        {
            if (null == List || 0 == List.Length)
                return string.Empty;

            StringBuilder syncString = new StringBuilder();

            foreach (SyncKeyPair keyVal in List)
            {
                if (0 != syncString.Length)
                    syncString.Append("|");

                syncString.AppendFormat("{0}_{1}", keyVal.Key, keyVal.Val);
            }

            return syncString.ToString();
        }
    }

    public class SyncKeyPair
    {
        public string Key { get; set; }
        public string Val { get; set; }
    }
}